import React, { Component } from "react";
import './../taskmanage/Wofuzwderenwu.less'
import servies from "./../../servies";
import { Button, Form, Input,  Table, DatePicker, Space } from "antd";
const layout = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 16,
  },
};
export default class Wochuangjianderenwu extends Component {
  constructor(props) {
    super(props);
    this.onChange = this.onChange.bind(this);
    this.state = {
      list:[],
      id: "",
    newbiao: "",
    fenlei: "",
    newname: "",
    newdate: "",
    data:[],
    };
    this.del=this.del.bind(this)
  }
  romref = React.createRef();
  formRef = React.createRef();
  componentDidMount() {
    //发起请求
   servies.GetXinwenguanli().then((data)=>{
    console.log(data);
    this.setState({
      data:data
    })
   })
  }
  onReset = () => {
    this.formRef.current.resetFields();
  };
  onChange = (e) => {
    e.preventDefault()
    console.log("value", e.target.value);
    let key = e.target.dataset.key;
    this.setState({ [key]: e.target.value });
  };
  // 删除
  del(index){
    // this.showDeleteConfirm()
    const data = [...this.state.data];
    data.splice(index,1)
    this.setState({
      data
    })
  }
  render() {
    const columns = [
      {
        title: "序号",
        dataIndex: "id",
        key: "id",
        fixed: "true",
        align: "center",
      },
      {
        title: "标题",
        dataIndex: "newbiao",
        key: "1",
        align: "center",
      },
      {
        title: "分类",
        dataIndex: "fenlei",
        key: "2",
        align: "center",
      },
      {
        title: "创建人",
        dataIndex: "newname",
        key: "3",
        align: "center",
      },
      {
        title: "创建时间",
        dataIndex: "newdate",
        key: "4",
        align: "center",
      },
    
      {
        title: "操作",
        key: "operation",
        fixed: "true",
        render: (index) =>
        <>
        <span className="actions">编辑</span>
        <span className="actions" onClick={()=>this.del(index)}>删除</span>
         <span className="actions">详情</span>
        </>,
        align: "center",
      },
    ];
    return (
      <>
        <Form
          {...layout} ref={this.formRef} name="control-ref"  onFinish={this.onFinish} >
          <Form.Item name="newbiao" label="标题">
            <Input />
          </Form.Item>
          <Form.Item name="newname" label="创建人">
            <Input />
          </Form.Item>
          <Form.Item name="newdate" label="创建时间">
            <Space direction="vertical">
              <DatePicker placeholder="" />
            </Space>
          </Form.Item>
        </Form>
         <div className="ant-btn-block">
            <Button type="primary" htmlType="submit">查询</Button>
            <Button htmlType="button" onClick={this.onReset}>重置</Button>
            </div>
            <div className="ant-btn-block">
            <Button type="primary" htmlType="submit">新增</Button>
            <Button htmlType="button">分类管理</Button>
            </div>
      <Table columns={columns} dataSource={this.state.data} scroll={{}} />
      </>
    );
  }
}